﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MuYue.Plugin
{
    public class IPlugin<T> where T : class
    {
        /// <summary>
        /// 使用完整类名进行创建
        /// </summary>
        /// <param name="identify"></param>
        public IPlugin(string identify) {
            var manager = PluginManager.Create();
            this.container = manager.GetContainerByClassName(identify);
        }

        /// <summary>
        /// 缓存插件创建容器
        /// </summary>
        private readonly PluginContainer container;
        
        /// <summary>
        /// 插件创建方法
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public T Create(params object[] args) {
            var obj = Activator.CreateInstance(container.PluginClassType, args);
			var t = obj as T;
            if (t != null) {
				return t;
            }
            throw new Exception("插件类型不一致");
        }
    }
}
